package com.sskj.market.presenter;

import android.util.Log;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;
import com.sskj.market.bean.AddressBean;
import com.sskj.market.bean.MyAddressBean;
import com.sskj.market.ui.activity.MyAddressActivity;

import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/07/26
 */
public class MyAddressPresenter extends BasePresenter<MyAddressActivity> {
    //获取地址
    public void getMyAddress(int page,boolean flag) {
        httpService.getMyAddress(page)
                .tag(this)
                .execute(new JsonCallBack<HttpData<MyAddressBean>>(flag?this:null) {
                    @Override
                    public void onSuccess(Response<HttpData<MyAddressBean>> response) {
                        mView.getAddressSuccess(response.body().getData());
                    }

                    @Override
                    public void onError(Response<HttpData<MyAddressBean>> response) {
                        super.onError(response);
                        mView.getAddressSuccess(null);
                    }
                });
    }

    //删除地址
    public void onDeleteAddress(int id) {
        httpService.onDeleteAddress(id)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        mView.onDeleteAddressSuccess();
                    }
                });
    }

    //设置默认
    public void setDetailAddress(int id) {
        httpService.setDetailAddress(id)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        mView.setDetailAddressSuccess();
                    }
                });
    }

}
